package com.htrq.dao;

import java.util.List;

import org.apache.poi.hssf.record.formula.functions.T;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.htrq.entity.HRole;
import com.htrq.entity.TResource;
import com.htrq.entity.User;
@Repository
public class LoginDao extends BaseDaoImpl<T>{

	public List<TResource> getRightByUser(User user) {
		HRole role=(HRole) getCurrentSession().get(HRole.class,user.getRolid() );
		String hql="select new com.htrq.entity.TResource (tr.id,tr.text,tr.parentId,tr.hrefTarget,tr.ifc,tr.remark) from HRole r,RoleRes rr,TResource tr where r.rid=rr.rolid and rr.resid=tr.id and r.rid="+role.getRid();
		Query query=getCurrentSession().createQuery(hql);
		//query.setInteger(role.getRid(), 0);
		//query.setResultTransformer(Transformers.aliasToBean(TResource.class));
		return query.list();
	}

	public User getUser(String uname) {
		String hql="from User where uname='"+uname+"'";
		Query query=getCurrentSession().createQuery(hql);
		List<User> list=query.list();
		if(list.size()>0){
			return list.get(0); 
		}
		return null;
	}
	
}
